package com.mxpio.erp.mes.controller;

import com.mxpio.erp.common.mes.entity.ManufactureWorkOrderTaskSplit;
import com.mxpio.erp.common.mes.service.ManufactureWorkOrderTaskSplitService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.List;

@Tag(name = "ManufactureWorkOrderTaskSplitController", description = "生产订单-工单-工序任务-分批报工接口")
@RestController
@RequestMapping("/erp/mes/mowo/task/split/")
public class ManufactureWorkOrderTaskSplitController {
	@Autowired
	private ManufactureWorkOrderTaskSplitService service;

	@GetMapping("list")
	@Operation(summary = "生产订单-工单-工序任务-分批报工列表", description = "获取生产订单-工单-工序任务-分批报工列表", method = "GET")
	public Result<List<ManufactureWorkOrderTaskSplit>> list(Criteria criteria) throws UnsupportedEncodingException {
		List<ManufactureWorkOrderTaskSplit> items = service.list(ManufactureWorkOrderTaskSplit.class, criteria);
		return Result.OK(items);
	}
	
	@GetMapping("page")
	@Operation(summary = "生产订单-工单-工序任务-分批报工列表", description = "获取生产订单-工单-工序任务-分批报工列表", method = "GET")
	public Result<Page<ManufactureWorkOrderTaskSplit>> page(Criteria criteria, Integer pageSize, Integer pageNo) throws UnsupportedEncodingException {
		Pageable page = PageRequest.of(pageNo-1, pageSize);
		Page<ManufactureWorkOrderTaskSplit> items = service.listPage(ManufactureWorkOrderTaskSplit.class, page, criteria);
		return Result.OK(items);
	}
	
	@GetMapping("list/{taskCode}")
	@Operation(summary = "根据taskCode获取生产订单-工单-工序任务-分批报工", description = "根据taskCode获取生产订单-工单-工序任务-分批报工", method = "GET")
	public Result<List<ManufactureWorkOrderTaskSplit>> getListByTaskCode(@PathVariable(name = "taskCode", required = true) String taskCode) {
		Criteria criteria = Criteria.create();
		criteria.addCriterion("taskCode", Operator.EQ, taskCode);
		List<ManufactureWorkOrderTaskSplit> list = service.list(ManufactureWorkOrderTaskSplit.class, criteria);
		return Result.OK(list);
	}


}
